//
//  NSString+DelZero.m
//  ZBKY
//
//  Created by 罗壮燊 on 2016/11/2.
//  Copyright © 2016年 . All rights reserved.
//

#import "NSString+DelZero.h"

@implementation NSString (DelZero)

+ (NSString *)delZero:(double)number
{
    return [[NSString stringWithFormat:@"%.2f", number] delZero];
}

- (NSString *)delZero
{
    NSArray *strs = [self componentsSeparatedByString:@"."];
    NSString *str = strs.lastObject;
    str = [str substringWithRange:NSMakeRange(0, 2)];
    if ([str hasSuffix:@"0"]) {
        str = [str substringWithRange:NSMakeRange(0, 1)];
        if ([str hasPrefix:@"0"]) {
            str = @"";
        } else {
            str = [@"." stringByAppendingString:str];
        }
    } else {
        str = [@"." stringByAppendingString:str];
    }
    
    return [strs.firstObject stringByAppendingString:str];
}

@end
